package org.huangrui.redis.utils;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

/**
 * @Author hr
 * @Create 2024-05-15 22:57
 */
@Slf4j
@Component
public class CheckUtils {
    // @Qualifier(value = "redisTemplate")
    // @Autowired(required = false)
    @Resource
    private RedisTemplate<Object,Object> redisTemplate;
    public boolean checkWithBloomFilter(String checkItem,String key)
    {
        int hashValue = Math.abs(key.hashCode());
        long index = (long)(hashValue % Math.pow(2,32));
        Boolean existOK = redisTemplate.opsForValue().getBit(checkItem, index);
        log.info("--->key:"+key+" 对应坑位下标index: "+index+" 是否存在："+existOK);
        return existOK;
    }
}
